﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import org.aswing.*;
    import Transactions.*;
    import Classes.util.*;
    import Classes.effects.*;
    import flash.filters.*;
    import org.aswing.geom.*;
    import GameMode.*;
    import Display.aswingui.*;
    import Engine.*;
    import Modules.stats.types.*;
    import Modules.quest.Helpers.*;

    public class Wilderness extends Decoration {

        private static const STATUS_Y_OFFSET:int = 22;

        private const WILDERNESS:String = "wilderness";
        private const ACTIONBAR_OFFSET_X:int = 0;
        private const ACTIONBAR_OFFSET_Y:int = -15;
        protected const DEFAULT_PICKUP_ANIM:String = "static";

        protected var m_pickupAnims:Array;
        protected var m_isBeingMoved:Boolean = false;
        private var m_heldEnergy:Number = 0;

        public function Wilderness(_arg1:String=null){
            var _local2:XML;
            super(_arg1);
            m_objectType = WorldObjectTypes.WILDERNESS;
            setState(STATE_STATIC);
            m_typeName = this.WILDERNESS;
            m_ownable = false;
            if (m_item.xml.pickupAnim){
                this.m_pickupAnims = new Array();
                for each (_local2 in m_item.xml.pickupAnim) {
                    this.m_pickupAnims.push(new String(_local2.@name));
                };
            } else {
                this.m_pickupAnims = [this.DEFAULT_PICKUP_ANIM];
            };
        }
        public function getPickupAnim():String{
            return (MathUtil.randomElement(this.m_pickupAnims));
        }
        override public function onPlayAction():void{
            if (m_visitReplayLock > 0){
                return;
            };
            m_actionMode = PLAY_ACTION;
            if (((!(Global.isVisiting())) && (Global.world.m_territory.pointInTerritory(m_position.x, m_position.y)))){
                if (Global.player.checkEnergy(-(m_item.clearEnergyCost))){
                    Global.world.citySim.pickupManager.enqueue("NPC_lumberjack", this);
                } else {
                    displayStatus(ZLoc.t("Main", "NotEnoughEnergyRed"));
                };
            };
        }
        override public function onVisitPlayAction():void{
            Global.world.citySim.pickupManager.enqueue("NPC_lumberjack", this);
            trackVisitAction(TrackedActionType.REMOVE_WILDERNESS);
        }
        override public function clearFromMap():void{
            var _local1:int;
            var _local2:int;
            if (Global.isVisiting()){
                _local1 = Global.gameSettings.getInt("friendVisitWildernessRepGain", 1);
                _local2 = Global.gameSettings.getNumber("friendHelpDefaultCoinReward", 10);
                finalizeAndAwardVisitorHelp(VisitorHelpType.WILDERNESS_CLEAR, _local1, _local2);
            };
            super.clearFromMap();
        }
        override public function onVisitReplayAction(_arg1:TRedeemVisitorHelpAction):Number{
            if (this.isLocked()){
                return (0);
            };
            m_actionMode = VISIT_REPLAY_ACTION;
            GameTransactionManager.addTransaction(_arg1);
            this.getProgressBarEndFunction()();
            var _local2:Number = super.onVisitReplayAction(null);
            m_actionMode = NO_ACTION;
            return (_local2);
        }
        override public function isVisitorInteractable():Boolean{
            return (true);
        }
        override protected function displayStatusStartPos():Point{
            var _local1:Point = IsoMath.tilePosToPixelPos(m_position.x, m_position.y);
            if (m_displayObject){
                _local1.y = (_local1.y - STATUS_Y_OFFSET);
            };
            return (IsoMath.viewportToStage(_local1));
        }
        override public function getCursor():Class{
            if ((((Global.world.getTopGameMode() is GMEditMove)) || ((Global.world.getTopGameMode() is GMObjectMove)))){
                return (EmbeddedArt.hud_act_move);
            };
            if (((Global.player.checkEnergy(-(m_item.clearEnergyCost), false)) || (Global.isVisiting()))){
                return (EmbeddedArt.hud_act_clearWilderness);
            };
            return (null);
        }
        override public function getCustomCursor():Object{
            var _local3:ASFont;
            var _local4:GlowFilter;
            var _local5:MarginBackground;
            if (!m_customCursor){
                m_customCursor = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
                m_customCursorLabel = new JLabel("");
                m_customCursorHolder = new Sprite();
                Global.ui.addChild(m_customCursorHolder);
                m_customCursorWindow = new JWindow(m_customCursorHolder);
                _local3 = ASwingHelper.getBoldFont(16);
                _local4 = new GlowFilter(0, 1, 1.2, 1.2, 20, BitmapFilterQuality.HIGH);
                m_customCursorLabel.setForeground(new ASColor(0xFFFFFF));
                m_customCursorLabel.setFont(_local3);
                m_customCursorLabel.setTextFilters([_local4]);
            };
            var _local1:DisplayObject;
            var _local2:GameMode = Global.world.getTopGameMode();
            if ((((((_local2 is GMEditMove)) || ((_local2 is GMObjectMove)))) && (this.isMoveLocked))){
                _local1 = (new EmbeddedArt.hud_act_move() as DisplayObject);
                m_customCursorLabel.setText(m_item.unlockMovementEnergyCost.toString());
            } else {
                if ((((_local2 is GMEditMove)) || ((((_local2 is GMObjectMove)) && (!(this.isMoveLocked)))))){
                    _local1 = (new EmbeddedArt.hud_act_move() as DisplayObject);
                    m_customCursorLabel.setText("");
                } else {
                    if ((((_local2 is GMPlay)) || ((_local2 is GMEditSell)))){
                        _local1 = (new EmbeddedArt.hud_act_clearWilderness() as DisplayObject);
                        m_customCursorLabel.setText(m_item.clearEnergyCost.toString());
                    } else {
                        return (null);
                    };
                };
            };
            if (_local1){
                _local5 = new MarginBackground(_local1, new Insets(0, 0, 0, 0));
                m_customCursor.setBackgroundDecorator(_local5);
                m_customCursor.setPreferredSize(new IntDimension(_local1.width, _local1.height));
                m_customCursor.setMinimumSize(new IntDimension(_local1.width, _local1.height));
                m_customCursor.setMaximumSize(new IntDimension(_local1.width, _local1.height));
            };
            m_customCursor.append(m_customCursorLabel);
            m_customCursorWindow.setContentPane(m_customCursor);
            ASwingHelper.prepare(m_customCursorWindow);
            m_customCursorWindow.show();
            return (m_customCursorWindow);
        }
        override public function isSellable():Boolean{
            return (true);
        }
        override public function sell():void{
            this.onPlayAction();
        }
        override public function canBeDragged():Boolean{
            if ((Global.world.getTopGameMode() is GMEditRotate)){
                return (false);
            };
            return (((!((m_actionMode == PLAY_ACTION))) && (!((m_actionMode == VISIT_PLAY_ACTION)))));
        }
        override public function onMenuClick(_arg1:MouseEvent):void{
        }
        override public function usingTileHighlight():Boolean{
            if ((Global.world.getTopGameMode() is GMEditRotate)){
                return (false);
            };
            return (true);
        }
        override public function overrideCursor():Boolean{
            var _local1:Boolean;
            return (_local1);
        }
        override public function onMouseOver(_arg1:MouseEvent):void{
            super.onMouseOver(_arg1);
        }
        override public function onMouseOut():void{
            super.onMouseOut();
        }
        override public function getToolTipHeader():String{
            return (null);
        }
        override public function getToolTipAction():String{
            var _local3:Boolean;
            var _local1 = "";
            var _local2:GameMode = Global.world.getTopGameMode();
            if ((_local2 is GMEditMove)){
                if (m_isMoveLocked){
                    _local3 = ((!(Global.world.isUnlockingMove)) && (Global.player.checkEnergy(-(m_item.unlockMovementEnergyCost), false)));
                    if (_local3){
                        _local1 = ZLoc.t("Main", "UprootToMove");
                    } else {
                        if (Global.world.isUnlockingMove){
                            _local1 = ZLoc.t("Main", "UprootWait");
                        } else {
                            _local1 = ZLoc.t("Main", "NeedEnergy", {amount:m_item.unlockMovementEnergyCost});
                        };
                    };
                };
            } else {
                if ((_local2 is GMObjectMove)){
                } else {
                    if (m_item){
                        if (Global.player.checkEnergy(-(m_item.clearEnergyCost), false)){
                            _local1 = ZLoc.t("Main", "WildernessToolTip");
                        } else {
                            _local1 = ZLoc.t("Main", "NeedEnergy", {amount:m_item.clearEnergyCost});
                        };
                    };
                };
            };
            return (_local1);
        }
        override public function set isMoveLocked(_arg1:Boolean):void{
            m_isMoveLocked = _arg1;
            removeAnimatedEffects();
            if (m_isMoveLocked){
                addAnimatedEffect(EffectType.DARKEN);
            };
        }
        override public function getActionText():String{
            return (ZLoc.t("Main", "Clearing"));
        }
        override public function unlockMovement():void{
            this.m_isBeingMoved = true;
            super.unlockMovement();
        }
        override public function getProgressBarStartFunction():Function{
            return (function ():Boolean{
                if (m_isBeingMoved){
                    if (!Global.player.checkEnergy(-(m_item.unlockMovementEnergyCost))){
                        displayStatus(ZLoc.t("Main", "NotEnoughEnergyRed"));
                        return (false);
                    };
                    doEnergyChanges(-(m_item.unlockMovementEnergyCost), new Array("energy", "expenditures", "unlock_movement", m_item.name));
                    Global.player.heldEnergy = (Global.player.heldEnergy + m_item.unlockMovementEnergyCost);
                    m_heldEnergy = m_item.unlockMovementEnergyCost;
                } else {
                    if (!Global.isVisiting()){
                        if (m_actionMode != VISIT_REPLAY_ACTION){
                            if ((((m_actionMode == PLAY_ACTION)) && (!(Global.player.checkEnergy(-(m_item.clearEnergyCost)))))){
                                displayStatus(ZLoc.t("Main", "NotEnoughEnergyRed"));
                                return (false);
                            };
                            doEnergyChanges(-(m_item.clearEnergyCost), new Array("energy", "expenditures", "remove_widerness", m_item.name));
                            Global.player.heldEnergy = (Global.player.heldEnergy + m_item.clearEnergyCost);
                            m_heldEnergy = m_item.clearEnergyCost;
                        };
                    } else {
                        return (true);
                    };
                };
                return (true);
            });
        }
        override public function getProgressBarEndFunction():Function{
            return (function ():void{
                Global.player.heldEnergy = (Global.player.heldEnergy - m_heldEnergy);
                if (m_isBeingMoved){
                    m_isBeingMoved = false;
                } else {
                    clearFromMap();
                };
            });
        }
        override public function getProgressBarCancelFunction():Function{
            Global.player.heldEnergy = (Global.player.heldEnergy - this.m_heldEnergy);
            return (super.getProgressBarCancelFunction());
        }
        override public function getProgressBarOffset():Point{
            return (new Point(this.ACTIONBAR_OFFSET_X, this.ACTIONBAR_OFFSET_Y));
        }
        override public function getVisitReplayEquivalentActionString():String{
            return ("clear");
        }

    }
}//package Classes 
